﻿using Hidistro.Core;
using Hidistro.Core.Enums;
using Hidistro.Entities.Commodities;
using Hidistro.SaleSystem.Catalog;
using Hidistro.UI.Common.Controls;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using System.Xml;

namespace Hidistro.UI.SaleSystem.Tags
{
    public class YB_Store_CategoryTopProduct : AscxTemplatedWebControl
    {
        private Repeater PList;
        public string Cname;
        private DataTable GetProductList(int categoryid, int MaxNum)
        {
            SubjectListQuery query = new SubjectListQuery
            {
                SortBy = "ShowSaleCounts",
                SortOrder = SortAction.Desc,
                CategoryIds = categoryid.ToString(),
                MaxNum = MaxNum
            };
            return ProductBrowser.GetSubjectList(query);
        }
        private void PList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                CategoryInfo ci = (CategoryInfo)e.Item.DataItem;
                Repeater FList = (Repeater)e.Item.FindControl("FList");

                System.Collections.Generic.List<JSShop.Model.vw_Hishop_BrowseProductList> l= new List<JSShop.Model.vw_Hishop_BrowseProductList>();
                l = new Juse.Interface.ProductBrowser().GetOrderByProductByOneCategoryId(ci.CategoryId, "ShowSaleCounts desc", 10);
                FList.DataSource = l;
                FList.DataBind();
            }
        }
        protected override void AttachChildControls()
        {
            this.PList = (Repeater)this.FindControl("PList");
            this.PList.ItemDataBound += PList_ItemDataBound;
        }
        protected override void OnInit(EventArgs e)
        {
            if (this.SkinName == null)
            {
                this.SkinName = "/ascx/tags/YB_Store_CategoryTopProduct.ascx";
            }
            base.OnInit(e);
        }
        public object DataSource
        {
            get
            {
                return this.PList.DataSource;
            }
            set
            {
                this.EnsureChildControls();
                this.PList.DataSource = value;
            }
        }
        public override void DataBind()
        {
            this.EnsureChildControls();
            if (this.PList.DataSource != null) this.PList.DataBind();
        }
    }
}
